package cug.hexy.springbatchrabbitmqdemo.controller;

import cug.hexy.springbatchrabbitmqdemo.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("/send/{taskId}")
    public String sendTask(@PathVariable String taskId) {
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.TASK_EXCHANGE,
                "task.routing.key",
                taskId
        );
        return "任务 " + taskId + " 已发送！";
    }
}